<template>
    <router-view v-slot="{ Component }">
      <component :is="Component" />
    </router-view>
</template>

<script setup>
// 获取token并处理组件创建前的逻辑
import { useStore } from 'vuex'

const store = useStore()
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
if (userInfo) {
  store.commit('setLoginState', true)
  store.commit('setUserInfo', userInfo)
}


// 解决element视窗大小调整ResizeObserver问题
const debounce = (fn, delay) => {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 16);
    super(callback);
  }
}
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // text-align: center;
  color: #2c3e50;
  // margin-top: 60px;
}
/* router过渡 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
</style>
